package kr.hkit.powerjava.chapter22.submit3;
//챕터22 프로그래밍5번 

import java.util.ArrayList;
import java.util.Collections;

class JumSu {
	private ArrayList<Double> arList;

	public JumSu(ArrayList<Double> arList) {
		this.arList = arList;
	}

	public boolean range(boolean r) { //범위 검사
		for (int i = 0; i < arList.size(); i++) {
			if (arList.get(i) < 0.0 || arList.get(i) > 10.0) {
				r = false;
			} else {
				r = true;
			}
		}
		return r;
	}
	
	
	public void prnRange() { //범위 확인
		if (range(true)) {
			System.out.println("정상 입력 되었습니다.");
		} else {
			System.out.println("0.0~10.0까지의 값만 입력하십시오.");
		}
	}
	
	public double getTotal() { //최고, 최저 제외 총점
		double total = 0;
		for (int j = 0; j < arList.size(); j++) {
			if (arList.get(j) == Collections.max(arList)
					|| arList.get(j) == Collections.min(arList)) { 
				continue;
			} else {
				total += arList.get(j);
			}
		}
		return total;
	}

	public double getAve() { //평균
		return getTotal() / (arList.size() - 2);
	}
}


public class JumSuTest {
	public static void main(String[] args) {
		ArrayList<Double> jum = new ArrayList<>();
		JumSu jum1 = new JumSu(jum);
		jum.add(5.5);
		jum.add(6.5);
		jum.add(7.2);
		jum.add(10.0);
		jum.add(10.0);
		jum.add(4.3);
		jum.add(6.8);
		jum.add(9.7);
		jum.add(3.7);
		jum.add(6.5); 

		System.out.println(jum);
		
		jum1.prnRange();
		
		System.out.println();
		System.out.print("최고점은? ");
		System.out.println(jum.get(jum.indexOf(Collections.max(jum))));

		System.out.print("최저점은? ");
		System.out.println(jum.get(jum.indexOf(Collections.min(jum))));
		System.out.println();

		System.out.printf("총점 : " + "%4.2f"+ "점", jum1.getTotal());
		System.out.println("\n"+"(최고점,최저점 제외)");
		System.out.printf("평균 : " + "%4.2f"+ "점", jum1.getAve());

	}
}

